package com.sg.service.base.framework.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sg.common.util.CommonFunctionHelper;
import com.sg.dto.base.framework.req.BatchQueryBeginMembInfoListReq;
import com.sg.dto.base.framework.req.BatchQueryOriginalRoleMemberInfoTestDataReq;
import com.sg.dto.base.framework.req.QueryBeginMembInfoDetailReq;
import com.sg.dto.base.framework.req.QueryBeginMembInfoListReq;
import com.sg.entity.OriginalRoleMemberInfo;
import com.sg.service.base.framework.MOriginalRoleMemberInfoService;
import com.wicket.okrframework.common.dto.FieldInfo;
import com.wicket.okrframework.common.exception.BizException;
import com.wicket.okrframework.dal.mapper.mbg.OriginalRoleMemberInfoMapper;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ：
 * @version 1.0
 * @since 2022/1/19 15:39
 */
@Service
public class MOriginalRoleMemberInfoServiceImpl
        extends ServiceImpl<OriginalRoleMemberInfoMapper, OriginalRoleMemberInfo>
        implements MOriginalRoleMemberInfoService {

    @Autowired
    OriginalRoleMemberInfoMapper originalRoleMemberInfoMapper;

    /**
     * 1-2-10批量查询身份人员资料列表[1014]
     * gen by moon at 10/23/2022, 2:25:54 PM
     */
    @Trace(operationName = "1-2-10批量查询身份人员资料列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OriginalRoleMemberInfo> batchQueryBeginMembInfoList(BatchQueryBeginMembInfoListReq reqDto) {

        try {
            QueryWrapper<OriginalRoleMemberInfo> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            if (reqDto.getBeginMembInfoList() == null || reqDto.getBeginMembInfoList().isEmpty()) {
                return new ArrayList<>();
            }
            queryWrapper.in("original_role_member_id", reqDto.getBeginMembInfoList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OriginalRoleMemberInfo.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OriginalRoleMemberInfo.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OriginalRoleMemberInfo.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OriginalRoleMemberInfo>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 1-2-10查询身份人员资料详情[116]
     * gen by moon at 3/31/2023, 3:24:02 AM
     */
    @Trace(operationName = "1-2-10查询身份人员资料详情")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public OriginalRoleMemberInfo queryBeginMembInfoDetail(QueryBeginMembInfoDetailReq reqDto) {

        try {
            reqDto.setIsValid("FALSE");
            QueryWrapper<OriginalRoleMemberInfo> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OriginalRoleMemberInfo> retList = super.list(queryWrapper);
            if (retList != null && retList.size() > 0) {
                OriginalRoleMemberInfo retData = retList.get(0);

                return retData;
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * 1-2-10新增身份人员资料[113]
     * gen by moon at 10/23/2022, 2:25:51 PM
     */
    @Trace(operationName = "1-2-10新增身份人员资料")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String addBeginMembInfo(OriginalRoleMemberInfo originalRoleMemberInfo) {
        originalRoleMemberInfo.setOriginalStafInfoId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
        originalRoleMemberInfo.setIsValid("FALSE");
        originalRoleMemberInfo.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        originalRoleMemberInfo.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
        if (super.save(originalRoleMemberInfo)) {
            return originalRoleMemberInfo.getOriginalStafInfoId();
        } else {
            return "-1";
        }

    }

    /**
     * 1-2-10批量修改改身份人员资料[1618]
     * gen by moon at 10/23/2022, 2:25:56 PM
     */
    @Trace(operationName = "1-2-10批量修改改身份人员资料")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchUpdateBeginMembInfo(List<OriginalRoleMemberInfo> originalRoleMemberInfo) {

        if (originalRoleMemberInfo == null || originalRoleMemberInfo.size() == 0) {
            return false;
        }
        return super.saveOrUpdateBatch(originalRoleMemberInfo);

    }

    /**
     * 1-2-10批量删除身份人员资料[1616]
     * gen by moon at 10/23/2022, 2:25:55 PM
     */
    @Trace(operationName = "1-2-10批量删除身份人员资料")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchDeleteBeginMembInfo(List<String> reqDto) {

        if (reqDto == null || reqDto.size() == 0) {
            return false;
        }

        return super.removeByIds(reqDto);
    }

    /**
     * 1-2-10删除身份人员资料[115]
     * gen by moon at 10/23/2022, 2:25:52 PM
     */
    @Trace(operationName = "1-2-10删除身份人员资料")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBeginMembInfo(String originalStafInfoId) {

        return super.removeById(originalStafInfoId);
    }

    /**
     * 1-2-10修改身份人员资料[114]
     * gen by moon at 10/23/2022, 2:25:52 PM
     */
    @Trace(operationName = "1-2-10修改身份人员资料")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateBeginMembInfo(OriginalRoleMemberInfo originalRoleMemberInfo) {

        return super.updateById(originalRoleMemberInfo);
    }

    /**
     * 1-2-10查询身份人员资料列表[4016]
     * gen by moon at 10/23/2022, 2:25:56 PM
     */
    @Trace(operationName = "1-2-10查询身份人员资料列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OriginalRoleMemberInfo> queryBeginMembInfoList(QueryBeginMembInfoListReq reqDto) {

        try {
            QueryWrapper<OriginalRoleMemberInfo> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID

            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OriginalRoleMemberInfo.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OriginalRoleMemberInfo.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OriginalRoleMemberInfo.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OriginalRoleMemberInfo>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * M1批量查询身份人员资料测试[4863]
     * gen by moon at 10/23/2022, 2:25:57 PM
     */
    @Trace(operationName = "M1批量查询身份人员资料测试")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<OriginalRoleMemberInfo> batchQueryOriginalRoleMemberInfoTestData(BatchQueryOriginalRoleMemberInfoTestDataReq reqDto) {

        try {
            QueryWrapper<OriginalRoleMemberInfo> queryWrapper = new QueryWrapper<>();

            if (reqDto.getOriginalRoleMemberInfoTestDataList() == null || reqDto.getOriginalRoleMemberInfoTestDataList().isEmpty()) {
                return new ArrayList<>();
            }
            queryWrapper.in("original_role_member_id", reqDto.getOriginalRoleMemberInfoTestDataList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OriginalRoleMemberInfo.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OriginalRoleMemberInfo.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper, likeList, fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OriginalRoleMemberInfo.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OriginalRoleMemberInfo>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1", e, false);
        }
    }

    /**
     * M1批量删身份人员资料测试[4864]
     * gen by moon at 10/23/2022, 2:25:58 PM
     */
    @Trace(operationName = "M1批量删身份人员资料测试")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchDeleteOriginalRoleMemberInfoTestData(List<String> reqDto) {

        if (reqDto == null || reqDto.size() == 0) {
            return false;
        }

        return super.removeByIds(reqDto);
    }
}
